package com.itheima.controller;

import com.itheima.mapper.ClazzMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result getClazz(ClazzQueryParam clazzQueryParam) {
        log.info("根据条件查询班级信息 {}",clazzQueryParam);
        PageResult<Clazz> pageResult = clazzService.Page(clazzQueryParam);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result addClazz(@RequestBody  Clazz clazz) {
        log.info("添加班级 {}",clazz);
        clazzService.insert(clazz);
        return  Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteClazz(@PathVariable Integer id) {
        log.info("根据id删除部门 {}",id);
        clazzService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getClazzById(@PathVariable Integer id) {
        log.info("根据id查询部门 {}",id);
       Clazz clazz =  clazzService.getById(id);
        return Result.success(clazz);
    }
    @PutMapping
    public Result updateClazz(@RequestBody Clazz clazz) {
        log.info("修改部门 ",clazz);
       clazzService.updateById(clazz);
        return Result.success();
    }
    @GetMapping("/list")
    public Result getClazzList() {
        log.info("查询全部部门数据");
        List<Clazz> clazzList = clazzService.selectAll();
        return Result.success(clazzList);
    }
}
